package com.zbkj.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.dal.entity.user.UserSearch;
import com.zbkj.dal.dao.UserSearchDao;
import com.zbkj.service.model.dto.UserSearchHistoryDTO;
import com.zbkj.service.service.UserSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 484
 */
@Service
public class UserSearchServiceImpl extends ServiceImpl<UserSearchDao, UserSearch> implements UserSearchService {

    @Autowired
    private UserSearchDao userSearchDao;

    @Override
    public List<UserSearchHistoryDTO> findUserSearchHistory(Integer userId) {
        LambdaQueryWrapper<UserSearch> lqw = Wrappers.lambdaQuery();
        lqw.eq(UserSearch::getUserId, userId);
        lqw.eq(UserSearch::getDeleted, 0);
        lqw.orderBy(true, false, UserSearch::getCreateTime);
        return userSearchDao.selectList(lqw).stream().map(UserSearchHistoryDTO::new).collect(Collectors.toList());
    }

    @Override
    public Integer userHotKeywordsDel(List<Integer> ids) {
        LambdaUpdateWrapper<UserSearch> luw = Wrappers.lambdaUpdate();
        luw.set(UserSearch::getDeleted, 1);
        luw.in(UserSearch::getId, ids);
        return userSearchDao.update(null, luw);
    }
}
